package com.ww.juc.threadpool.single;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class SingleThreadExecutorDemo {

    public static void main(String[] args) {
        ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 3; i++) {
            singleThreadExecutor.execute(new Runnable1("" + i + 1));
        }
        singleThreadExecutor.shutdown();
    }
}

class Runnable1 implements Runnable {
    
    private String username;
    
    public Runnable1(String username) {
        this.username = username;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " username = " + username + " begin " + System.currentTimeMillis());
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + " username = " + username + " end " + System.currentTimeMillis());
    }
    
}